﻿using BLL;
using COMMON;
using IBLL;
using MODEL;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Shop.Controllers
{
    public class ProductBrandController : BaseController<ProductBrand, IProductBrandBLL>
    {
       
        public override IProductBrandBLL Bll
        {
            get
            {
                return new ProductBrandBLL();
            }
        }
        // GET: ProductBrand
        public ActionResult Add(ProductBrand brand)
        {
            Bll.Add(brand);
            return Json(new { state = true, msg = "添加成功" });
        }
        
        public ActionResult GetAll(int draw, int pageSize, int pageIndex) {
            var list = Bll.Search(pageSize, pageIndex, false, x => true);
            var count = Bll.GetCount(x => true);

            var result = new
            {
                draw = draw,
                data = list,
                recordsTotal = count,
                recordsFiltered = count
            };
            return Json(result);
        }
        public ActionResult GetAllByAddProduct()
        {
            var result = Bll.GetAll();
            return Json(result, JsonRequestBehavior.AllowGet);
        }
        public ActionResult GetOne(int id) {

            var result = Bll.GetOne(id);
            return Json(result,JsonRequestBehavior.AllowGet);

        }
        [HttpPost]
        public  ActionResult Update(ProductBrand brand)
        {
            Bll.Update(brand);
            return Json(new { state = true, msg = "修改成功" });
        }
    }
}